#include<iostream>
using namespace std;
#include<vector>
#include<string>
class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0")
            return "0";
        int n = num1.size(), m = num2.size();
        string ans((m + n), '0');
        for (int i = n - 1; i >= 0; --i)
        {
            for (int j = m - 1; j >= 0; --j)
            {
                int pos = m + n - i - j - 2;
                int num = (num1[i] - '0') * (num2[j] - '0') + (ans[pos] - '0');
                ans[pos] = '0' + num % 10;
                ans[pos + 1] += num / 10;
            }
        }
        while (ans.back() == '0')
            ans.pop_back();
        reverse(ans.begin(), ans.end());
        return ans;
    }
};